import * as dgram from 'dgram';  
import { Socket } from 'dgram';  

// 创建一个 UDP 套接字  
const client: Socket = dgram.createSocket('udp4');  

// 定义要发送的消息和地址信息  
const message = Buffer.from('Hello, UDP packet!');  
const port = 41234;  
const host = '127.0.0.1';  

// 发送消息  
client.send(message, port, host, (err: Error | null) => {  
  if (err) {  
    console.error('Error sending UDP packet:', err);  
  } else {  
    console.log('UDP packet sent successfully');  
  }  

  // 关闭套接字  
  client.close();  
});